package pers.crayon.baseprogram.task;

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wangzg13
 * @since 2022/10/17
 */
public class TaskExecutorsTest {


    private static SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {
        ThreadPoolTaskScheduler threadPoolTaskScheduler = TaskExecutors.getThreadPoolTaskScheduler();
        int poolSize = threadPoolTaskScheduler.getPoolSize();
        System.out.println(poolSize);
        threadPoolTaskScheduler.schedule(new Runnable() {

            @Override
            public void run() {
                System.out.println(sDateFormat.format(new Date()).toString() + ":" + Thread.currentThread().getName());
                System.out.println("当前线程池大小:" + threadPoolTaskScheduler.getPoolSize() + ",当前活跃线程大小:" + threadPoolTaskScheduler.getActiveCount());
            }
        }, new CronTrigger("*/5 * * * * ?"));
    }
}
